package com.hitemole.screen;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.hitemole.controller.GameServerController;
import com.hitemole.game.GameCore;
import com.hitemole.manager.GameManager;
import com.hitemole.network.ServerGame;
import com.hitemole.view.GameWorldRenderer;


public class GameServerScreen implements Screen{
	private GameManager world;
	private GameWorldRenderer renderer;
	private GameServerController controller;
	private GameCore core;
	public GameServerScreen(GameCore core) {
		// TODO Auto-generated constructor stub
		this.core=core;
	}

	@Override
	public void render(float delta) {
		// TODO Auto-generated method stub
		Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);		
		controller.update(delta);
		
		renderer.render();
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub
		renderer.setSize(width,height);
		
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		Gdx.input.setInputProcessor(null);
		if(world==null)world = new GameManager(core);
		if(renderer==null)renderer = new GameWorldRenderer(world,false);
		if(controller==null)controller = new GameServerController(world);
	}
	
	public void restart(){
		world=null;
		renderer=null;
		controller=null;
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		switch(Gdx.app.getType()){
		case Android:
			ServerGame.serverGame.stopServer();
			controller.pause();
			break;
		case Applet:
			break;
		case Desktop:
			break;
		case WebGL:
			break;
		case iOS:
			break;
		default:
			break;
		}
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		core.resumeScreen(this);
		core.setScreen(core.getResourceScreen());
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}
}
